package com.hbnu.controller;

import com.hbnu.pojo.Admin;
import com.hbnu.service.AdminLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/")
public class AdminLoginController {
    @Autowired
    private AdminLoginService adminLoginService;

//    管理员登录验证 比对数据库信息是否正确
    @RequestMapping("/Admin")
    public String login(Admin admin, HttpSession session) {
        String name = admin.getName();
        Integer pwd1= admin.getPwd1();
        Integer num=admin.getNum();
        if (!name.equals("") && !pwd1.equals("")&&!num.equals("")) {
            Admin admin1 = adminLoginService.login(admin);
            if (admin != null) {
                session.setAttribute("admin1", admin1);
            } else {
                session.setAttribute("失败", "错误");
                return "";//失败返回登录界面，是其再次登录
            }
        }
        return "";// 成功，进入管理员界面
    }
}



